params ["_unit"];

if(isNull _unit || {!alive _unit}) exitWith{};


//迫击炮
if((typeOf (vehicle _unit)) find "_Mortar_" >= 0) then
{
	[_unit] spawn fn_runSupportMort;
};


_unit addEventHandler ["killed", 
{
	private _unit = _this select 0;
	private _veh = vehicle _unit;
	if(_veh == _unit || !alive _veh) exitWith{};
	//systemChat (typeOf vehicle _unit);
	private _near = _unit nearEntities ["Man", 50];
	{
		if(!(isPlayer _x)
		&& {side _x != east} 
		&& {typeOf _x != "I_Story_Officer_01_F"} 
		&& {_x getVariable ["as_event_sup", 0] == 0}) exitWith
		{	
			_x setVariable ["as_event_sup", 1];
			[_x, _veh, position _veh] spawn
			{
				params ["_x", "_veh", "_pos"];
				_x doMove _pos;
				waitUntil 
				{
					(!alive _x)
					|| {side _x == east}
					|| {_x distance _veh < 5}
				};
				
				if(alive _x && {side _x != east}) then
				{
					doStop _x;
					_x assignAsGunner _veh;
					[_x] orderGetIn true;
					_x moveInGunner _veh;
					[_x] call fn_eventSupport;
				};	
			};
			
		};
	}forEach _near;
}];


_unit spawn
{
	private _unit = _this;
	private _end = false;
	while{!_end} do
	{
		Sleep 20;
		if(isNull _unit || {!alive _unit}) then{_end = true;};
		
		if(simulationEnabled _unit) then{
			{
				if(_x distanceSqr _unit < 16) exitWith
				{
					moveOut _unit;//出来了还可能上去
				};
			}forEach (call fn_getPlayerRed);
		};
	};
};